/* smog_pollution_master: This script calls each of the programs used to prepare
the data and run the analysis for "Technology and the Effectiveness of Regulatory Programs 
Over Time: Vehicle Emissions and Smog Checks with a Changing Fleet," by Sanders and Sandler

Only the data needed for the final analysis was provided in the data archive, as the full Smog 
Check data used in the earlier build programs are extremely large. See readme file.  Programs
that rely on earlier raw or intermediate datasets are commented out in this script.  



*/

global path // Insert root of data archive here, ending in a forward slash

/************ Data Construction *************************/

/* Read in raw Smog Check data into a panel */
//do ${path}build/append_smogcheck.do

/* Clean the Smog Check Data, and calculate station quality scores*/

//do ${path}build/score_calc.do

/* Collapse the Smog Check data to a county-day panel */

//do ${path}build/smog_collapse

// Output: star_counties.dta

/* Combine the county-day panel with pollution and weather data*/

do ${path}build/pollution_smog_merge.do

// Output: pollution_star_merged.dta




/*********** Main Analysis ***********************************/

/* Produce summary statistics (Table 1) in the paper */

do ${path}analysis/smog_pollution_summary.do

// Output: summary.tex

/* Produce graph of vehicle emissions and failure rates by age (Figures 1 and A5) */

do ${path}analysis/smog_vehicle_emissions.do

// Output: modelyr_emissions.pdf

/* Produce regression tables for the effect of Smog Checks on pollution (Tables 2, 3, 4 and Figures 3 and A6)*/

do ${path}analysis/smog_pollution_analysis.do

//Output: buildup.tex, fpr_interaction.tex, ozone.tex, fpr_interaction_bin.pdf, ozone.pdf

/* Regression tables for PM10, which has weekly frequency and so is best handled in its own program (Table 5, figure A6)*/

do ${path}analysis/smog_pollution_pm10.do

//Output: pm10.tex, pm10_bin.pdf

/* Placebo test, "event study" plot (Figure 2). Note that an ado-file for the confidence intervals is also included*/

do ${path}analysis/smog_pollution_placebo.do

// Output: co_event_lags.pdf, nox_event_lags.pdf

/* Simulate the effect of improving station quality and eliminating Smog Check (FIgure 4) */

do ${path}analysis/smog_pollution_sim.do

// Output: fpr_mapdata.dta, fpr_sim_nox_map_98.png, fpr_sim_nox_map_09.png, fpr_sim_co_map_98.png, fpr_sim_co_map_09.png

/* Statistics on consumers who switch inspection stations between inspections within a cycle (table 6) */

do ${path}analysis/smog_mechanisms.do

// Output: mechanism_switchers.tex

/************ Appendix Material ******************************/

/* Robustness checks for main specification in Table 2 (Table A1, A2, A3, A4, A5) */

do ${path}appendix/smog_pollution_robustness.do

// Output: robustness_window.tex, robustness_age.tex, robustness.tex, robustness_trend.tex, robustness_iv

/* Robustness check using re-inspections per square mile */

do ${path}appendix/smog_pollution_analysis_per_sqmile.do

// Output: buildup_sqmile.tex



// Output: star_experiment.tex, no_smogcheck_sim.pdf

/* Plot residual variation in reinspections after controlling for covariates (Figure A2, A3)*/

do ${path}appendix/smog_pollution_trends.do

// Output: residuals_pre85.pdf, residuals_post85.pdf, share_pre85.pdf

/* Plot residual variation in pollution after controlling for different levels of fixed effects (Figure A4)*/

do ${path}appendix/smog_residual_trends.do

// Output: co_res_fe.pdf, co_res_cyfe.pdf, nox_res_fe.pdf, nox_res_cyfe.pdf

/* "First stage" graphs showing relationship between station quality measures and later emissions readings (Figures A8 and A9)*/

//do ${path}appendix/firststage.do

// Output: co_svfr_bin.pdf, co_fpr_bin.pdf, co_fpr_current_bin.pdf, nox_svfr_bin.pdf, nox_fpr_bin.pdf, nox_fpr_current_bin.pdf

/* Convert repair data into a county-year panel, for the simulations*/

//do ${path}appendix/prep_repair_data.do

// Output: repairs_county_year.dta

/* More detailed output from simulating implementing STAR and eliminating Smog Check (Table A7, Figure A10) */

do ${path}appendix/smog_pollution_sim_appendix.do
